package com.atguigu.flink.chapter5.transform;

import org.apache.flink.api.common.functions.FlatMapFunction;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.util.Collector;

/**
 * @Author lizhenchao@atguigu.cn
 * @Date 2020/12/19 14:56
 */
public class Flink04_Transform_Filter {
    public static void main(String[] args) throws Exception {
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
        env.setParallelism(1);
        DataStreamSource<Integer> source = env.fromElements(1, 1, 20, 3, 100);

        source
          //.filter(value -> value % 2 == 0)
          .flatMap(new FlatMapFunction<Integer, Integer>() {
              @Override
              public void flatMap(Integer value, Collector<Integer> out) throws Exception {
                  if(value % 2 == 1) out.collect(value);
              }
          })
          .print();


        env.execute();
    }
}
/*
这些function 都有一个Rich
 */
